<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.46">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #6e2b2a}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #642a2b}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #5e691e}
span.s1 {color: #0a2cb1}
span.s2 {color: #000000}
span.s3 {color: #5b6b1b}
span.s4 {color: #0f30ae}
span.s5 {color: #5e691e}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><b>WarpZ<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>Warp a buffer with a time pointer</b></p>
<p class="p2"><br></p>
<p class="p3">Inspired by Chad Kirby's SuperCollider2 Warp1 class, which was inspired by Richard Karpen's sndwarp for CSound. A granular time strecher and pitchshifter.</p>
<p class="p2"><br></p>
<p class="p3"><b>WarpZ.ar(numChannels, bufnum, pointer, freqScale, windowSize, envbufnum, overlaps,<span class="Apple-converted-space"> </span></b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>windowRandRatio, interp, zeroSearch, zeroStart, mul, add)</b></p>
<p class="p2"><br></p>
<p class="p3"><span class="Apple-tab-span">	</span><b>numChannels</b> - the number of channels in the soundfile used in bufnum.</p>
<p class="p3"><span class="Apple-tab-span">	</span><b>bufnum</b> - the buffer number of a mono soundfile.</p>
<p class="p3"><span class="Apple-tab-span">	</span><b>pointer</b> - the position in the buffer.<span class="Apple-converted-space">  </span>The value should be between 0 and 1, with 0 being the begining</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>of the buffer, and 1 the end.</p>
<p class="p3"><span class="Apple-tab-span">	</span><b>freqScale</b>- the amount of frequency shift. 1.0 is normal, 0.5 is one octave down, 2.0 is one octave up.</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>Negative values play the soundfile backwards.</p>
<p class="p3"><span class="Apple-tab-span">	</span><b>windowSIze</b> - the size of each grain window.</p>
<p class="p3"><b><span class="Apple-tab-span">	</span>envbufnum</b> - the buffer number containing a singal to use for the grain envelope. -1 uses a built-in<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>Hanning envelope.</p>
<p class="p3"><span class="Apple-tab-span">	</span><b>overlaps</b> - the number of overlaping windows.</p>
<p class="p3"><b><span class="Apple-tab-span">	</span>windowRandRatio </b>- the amount of randomness to the windowing function.<span class="Apple-converted-space">  </span>Must be between 0 (no</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>randomness) to 1.0 (probably to random actually)</p>
<p class="p3"><b><span class="Apple-tab-span">	</span>interp -<i> </i></b>the interpolation method used for pitchshifting grains. 1 = no interpolation. 2 = linear.<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>4 = cubic interpolation (more computationally intensive).</p>
<p class="p3"><span class="Apple-tab-span">	</span><b>zeroSearch -</b> if &gt; 0.0, the UGen will search through the buffer from the current 'pointer' looking for a<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>zero crossing in the signal to start the grain with. The search is limitied to zeroSearch seconds<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>(i.e., if zeroSearch is 0.01, the UGen will only try to find a zero crossing within 0.01 seconds of<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>the pointer).</p>
<p class="p3"><span class="Apple-tab-span">	</span><b>zeroStart -</b> if &gt; 0.0, an attempt will be made to scuedule the next grain according to a zero crossing</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>in the current grain. This value limits the search to zeroStart as a percentage of the current grain's</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>duration (i.e., if the current grain's duration is 0.2, and zeroStart is 0.1, the algorithm will attempt to<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>find the closest zero crossing in the current grain +/- 0.02 seconds from when the next grain was<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>originally scheduled according to windowSize / overlaps).</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p3"><b>Examples:</b></p>
<p class="p4"><br></p>
<p class="p5">s.boot;</p>
<p class="p4"><br></p>
<p class="p5">(</p>
<p class="p5"><span class="s1">var</span> winenv;</p>
<p class="p6">// a custom envelope - not a very good one, but you can hear the difference between this<span class="Apple-converted-space"> </span></p>
<p class="p6">// and the default</p>
<p class="p5">winenv = <span class="s1">Env</span>([0, 1, 0], [0.5, 0.5], [8, -8]);</p>
<p class="p7"><span class="s2">b = </span><span class="s1">Buffer</span><span class="s2">.read(s, </span>"sounds/a11wlk01-44_1.aiff"<span class="s2">);</span></p>
<p class="p5">z = <span class="s1">Buffer</span>.sendCollection(s, winenv.discretize, 1);</p>
<p class="p4"><br></p>
<p class="p5"><span class="s1">SynthDef</span>(<span class="s3">\warp</span>, {<span class="s1">arg</span> buffer = 0, envbuf = -1;</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s1">var</span> out, pointer, filelength, pitch, env, dir;</p>
<p class="p6"><span class="s2"><span class="Apple-tab-span">	</span></span>// pointer - move from beginning to end of soundfile over 15 seconds</p>
<p class="p5"><span class="Apple-tab-span">	</span>pointer = <span class="s1">Line</span>.kr(0, 1, 15);</p>
<p class="p6"><span class="s2"><span class="Apple-tab-span">	</span></span>// control pitch with MouseX</p>
<p class="p5"><span class="Apple-tab-span">	</span>pitch = <span class="s1">MouseX</span>.kr(0.5, 2);</p>
<p class="p5"><span class="Apple-tab-span">	</span>env = <span class="s1">EnvGen</span>.kr(<span class="s1">Env</span>([0.001, 1, 1, 0.001], [0.1, 14, 0.9], <span class="s3">'exp'</span>), doneAction: 2);</p>
<p class="p5"><span class="Apple-tab-span">	</span>out = <span class="s1">WarpZ</span>.ar(1, buffer, pointer, pitch, 0.1, envbuf, 8, 0.1, 2, 0.01, 0.1);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s1">Out</span>.ar(0, out * env);</p>
<p class="p5">}).send(s);</p>
<p class="p4"><br></p>
<p class="p5">)</p>
<p class="p4"><br></p>
<p class="p8">// use built-in env</p>
<p class="p9"><span class="s2">x = </span><span class="s4">Synth</span><span class="s2">(</span>\warp<span class="s2">, [</span>\buffer<span class="s2">, b, </span>\envbuf<span class="s2">, -1])</span></p>
<p class="p4"><br></p>
<p class="p8">// switch to the custom env</p>
<p class="p5">x.set(<span class="s5">\envbuf</span>, z)</p>
<p class="p5">x.set(<span class="s5">\envbuf</span>, -1);</p>
<p class="p4"><br></p>
<p class="p5">x.free;</p>
<p class="p4"><br></p>
<p class="p5">b.free;</p>
<p class="p5">z.free;</p>
</body>
</html>
